#include<iostream>
#include<vector>
#include<queue>
#include<cstring>
#include<cmath>
#include<map>
#include<set>
#include<cstdio>
#include<algorithm>
#define debug(a) cout<<#a<<"="<<a<<endl;
using namespace std;
const int maxn=2e5+1000;
typedef long long LL;
inline LL read(){LL x=0,f=1;char ch=getchar();	while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
return x*f;}
long long ans[maxn];
LL u[maxn];
long long sum[maxn];
vector<long long>g[maxn];
vector<long long>pre[maxn];
int main(void){
   LL t;t=read();
   while(t--){
      LL n;n=read();
      LL mx=0;
      for(LL i=0;i<n+10;i++) u[i]=0,ans[i]=0,g[i].clear(),sum[i]=0,pre[i].clear();
      for(LL i=1;i<=n;i++){
          u[i]=read();
          mx=max(mx,u[i]);
      }
      for(LL i=1;i<=n;i++){
          LL x;x=read();
          sum[u[i]]+=x;
          g[u[i]].push_back(x);
      }
      for(LL i=1;i<=mx;i++){
          sort(g[i].begin(),g[i].end());
      }
      for(LL i=1;i<=mx;i++){
          pre[i].push_back(0);
          for(LL j=0;j<g[i].size();j++){
              LL last=pre[i].size()-1;
              long long now=pre[i][last]+g[i][j];
              pre[i].push_back(now);
          }
      }
      for(LL i=1;i<=mx;i++){
          for(LL k=1;k<=n;k++){
              if(k>g[i].size()){
                 ans[k]+=0;
                 break;
              }
              else{
                 LL cnt=g[i].size()%k;
                 LL res=0;
                 res+=pre[i][cnt];
//                 for(LL j=0;j<cnt;j++){
//                    res+=g[i][j];
//                 }
                 ///debug(res);debug(i);debug(k);
                 ans[k]+=sum[i]-res;
              }
          }
//          cout<<"i="<<i<<": ";
//          for(LL k=1;k<=n;k++){
//              cout<<ans[k]<<" ";
//          }
//          cout<<"\n";
      }
      for(LL i=1;i<=n;i++){
         printf("%lld ",ans[i]);
      }printf("\n");
   }
   return 0;
}
